﻿namespace Mvc.Services {
    using System;
    using System.Collections.Generic;

    public class DefaultMessageService : IMessageService {
        public DefaultMessageService(ISimpleMessageService[] services) {
            Services = services;
            InstanceCreated = DateTime.Now;
        }

        public ISimpleMessageService[] Services { get; set; }
        private DateTime InstanceCreated { get; set; }
        
        #region IMessageService Members

        public string GetDefaultMessage() {
            return "Welcome to ASP.NET MVC!";
        }

        public string GetAboutMessage() {
            return "Check out ASP.NET MVC at http://www.asp.net/mvc";
        }

        public string GetInternalMessage() {
            return string.Format("This instance was created on {0}.", InstanceCreated);
        }

        public string[] GetMessages() {
            var messages = new List<string>();

            foreach (var messageService in Services) {
                messages.Add(messageService.GetMessage());
            }

            return messages.ToArray();
        }

        #endregion
    }
}
